package com.czxy.dao;

import com.czxy.domain.Commodity;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface CommodityMapper extends Mapper<Commodity> {

    @Select("SELECT * FROM commodity WHERE commodity_static = 1 ORDER BY `click_number` DESC")
    @Results(id = "commodity", value = {
            @Result(property = "commodityId", column = "commodity_Id"),
            @Result(property = "commodityName", column = "commodity_Name"),
            @Result(property = "commodityDetails", column = "commodity_Details"),
            @Result(property = "nowPrice", column = "now_Price"),
            @Result(property = "costPrice", column = "cost_Price"),
            @Result(property = "tradeWay", column = "trade_Way"),
            @Result(property = "tradeAddress", column = "trade_Address"),
            @Result(property = "phoneNumber", column = "phone_Number"),
            @Result(property = "qqNumber", column = "qq_Number"),
            @Result(property = "wxNumber", column = "wx_Number"),
            @Result(property = "whetherBot", column = "whether_Bot"),
            @Result(property = "clickNumber", column = "click_Number"),
            @Result(property = "commodityStatic", column = "commodity_Static"),
            @Result(property = "releaseDate", column = "release_Date"),
            @Result(property = "modificationDate", column = "modification_Date"),
            @Result(property = "classificationId", column = "classification_Id"),
            @Result(property = "uid", column = "uid"),
            @Result(property = "bid", column = "bid"),
            @Result(column = "commodity_id", property = "commodityImgList", javaType = List.class,
                    many = @Many(select = "com.czxy.dao.CommodityImgMapper.selectByCommodityId"))


    })
    public List<Commodity> selectMaxClickNum();

    @Select("SELECT * FROM commodity WHERE commodity_static = 1 ORDER BY `release_date` DESC")
    @ResultMap("commodity")
    public List<Commodity> selectNewestList();

    /**
     * 修改商品状态
     *
     * @param commodityId
     */
    @Update("update commodity set commodity_static = #{commodityStatic} where commodity_id = #{commodityId} and uid = #{uid}")
    public void updateStaticByUidAndCommodityId(@Param("uid") Integer uid, @Param("commodityId") String commodityId, @Param("commodityStatic") Integer commodityStatic);

    /**
     * 查询热门
     * @return
     */
    @Select("SELECT * FROM commodity WHERE commodity_static = 1 AND whether_bot != 0  ORDER BY `click_number` DESC")
    @ResultMap("commodity")
    List<Commodity> selectWhetherBotList();
}
